import "package:flutter/material.dart";

class RecommendMenuNewItem {
  String title;
  String cover;
  String? subTitle;
  RecommendMenuNewItem({
    required this.title,
    this.subTitle,
    required this.cover,
  });
}

// 推荐今日、最新、排行、福利菜单
class RecommendMenuNewWidget extends StatelessWidget {
  final List<RecommendMenuNewItem> list = [
    RecommendMenuNewItem(
      title: '今日上新',
      subTitle: '上新17',
      cover: "./images/tab_1.jpg",
    ),
    RecommendMenuNewItem(
      title: '抢先看',
      cover: "./images/tab_2.jpg",
    ),
    RecommendMenuNewItem(
      title: '排行榜',
      subTitle: 'GSC榜',
      cover: "./images/tab_3.jpg",
    ),
    RecommendMenuNewItem(
      title: '福利日历',
      subTitle: '签到+5',
      cover: "./images/tab_4.jpg",
    ),
  ];
  RecommendMenuNewWidget({super.key});
  @override
  Widget build(BuildContext context) {
    List<Widget> children = [];
    for (int i = 0; i < list.length; i++) {
      double rightEdge = i == (list.length - 1) ? 0 : 3;
      double leftEdge = i == 0 ? 0 : 3;
      RecommendMenuNewItem item = list[i];
      double height = 100;
      children.add(
        Expanded(
          child: Padding(
            padding: EdgeInsets.only(right: rightEdge, left: leftEdge),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(6),
              child: Stack(
                children: [
                  Container(
                    height: height,
                    width: double.infinity,
                    padding: const EdgeInsets.fromLTRB(4, 8, 4, 0),
                    decoration: const BoxDecoration(
                      color: Colors.white,
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(bottom: 3),
                          child: Text(
                            item.title,
                            style: const TextStyle(
                              color: Colors.black87,
                              fontSize: 13,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                        Image.asset(
                          item.cover,
                          fit: BoxFit.cover,
                          width: 40,
                          height: 50,
                        ),
                      ],
                    ),
                  ),
                  item.subTitle != null
                      ? Positioned(
                          bottom: 0,
                          left: 0,
                          right: 0,
                          child: Container(
                            padding:const EdgeInsets.all(1),
                            margin: const EdgeInsets.only(
                                left: 2, right: 2, bottom: 4),
                            decoration: BoxDecoration(
                                color: const Color.fromARGB(255, 241, 241, 241),
                                borderRadius: BorderRadius.circular(10)),
                            child: Text(
                              item.subTitle ?? '',
                              textAlign: TextAlign.center,
                              style: const TextStyle(fontSize: 11),
                            ),
                          ),
                        )
                      : const SizedBox(),
                ],
              ),
            ),
          ),
        ),
      );
    }
    return Row(
      children: children,
    );
  }
}
